import { createSlice } from "@reduxjs/toolkit"

const counterSlice = createSlice({
  name: "counter",
  initialState: {
    count: 99,
    message: "message" // 用来测试是不是更改了它，整个组件就刷新了
  },
  reducers: {
    addNumberAction(state, action) {
      state.count = state.count + action.payload
    },
    subNumberAction(state, action) {
      state.count = state.count - action.payload
    },
    changeMsgAction(state, action) {
      state.message = action.payload
    }
  }
})

export const { addNumberAction, subNumberAction, changeMsgAction } =
  counterSlice.actions
export default counterSlice.reducer
